// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   dealwith_ok.java

package qcs.crm_deliver;

import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class dealwith_ok extends HttpServlet
{

	public dealwith_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String stock_name = request.getParameter("stock_name");
				String stock_id = request.getParameter("stock_id");
				String qcs_id = request.getParameter("qcs_id");
				String apply_id = request.getParameter("apply_id");
				String dealwith_tag = request.getParameter("dealwith_tag");
				String product_id = request.getParameter("product_id");
				String qualified = request.getParameter("qualified");
				String unqualified_amount = request.getParameter("unqualified");
				String sql = (new StringBuilder("update qcs_crm_deliver set dealwith_tag='")).append(dealwith_tag).append("' where qcs_id='").append(qcs_id).append("'").toString();
				qcs_db.executeUpdate(sql);
				sql = (new StringBuilder("select * from qcs_apply where apply_id='")).append(apply_id).append("'").toString();
				ResultSet rs = qcs_db.executeQuery(sql);
				if (rs.next())
				{
					String crmDeliver_id = rs.getString("crmDeliver_id");
					String sql1 = (new StringBuilder("select * from stock_pre_paying where pay_id='")).append(rs.getString("crmDeliver_id")).append("'and product_id='").append(product_id).append("' and stock_id='").append(stock_id).append("'").toString();
					ResultSet rs1 = qcs_db.executeQuery(sql1);
					if (rs1.next())
					{
						Double qualified_amount_temp = Double.valueOf(Double.parseDouble(qualified) + rs1.getDouble("qualified_amount"));
						String sql2 = (new StringBuilder("update stock_pre_paying set qualified_amount='")).append(qualified_amount_temp).append("' where pay_id='").append(crmDeliver_id).append("' and product_id='").append(product_id).append("' and stock_id='").append(stock_id).append("'").toString();
						qcs_db.executeUpdate(sql2);
						sql = (new StringBuilder("update qcs_apply_details set qcs_tag='0',demand_amount='")).append(unqualified_amount).append("' where apply_id='").append(apply_id).append("'").toString();
						qcs_db.executeUpdate(sql);
					}
					sql = (new StringBuilder("update qcs_apply_details set qcs_tag='1' where apply_id='")).append(apply_id).append("' and demand_amount='0'").toString();
					qcs_db.executeUpdate(sql);
				}
				response.sendRedirect("qcs/crm_deliver/dealwith_ok.jsp?finished_tag=0");
				qcs_db.commit();
				qcs_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
